function _openDialogInfo($user_id){
	jQuery.post(BASE_URL+"admin/dataman/buyer/user_information",{user_id:$user_id},function(response){
		jQuery('#dialog').html(response);
		jQuery('#dialog').dialog(
			{
				 width: 950,
				 resizable: false,
				 height:500,
				 title: 'User Information' 
			}
		);
	});
}

function _active($user_id){
	jQuery.post(BASE_URL+"admin/dataman/buyer/activate",{user_id:$user_id},function(response){
		window.location.reload();
	});
}

function _deactive($user_id){
	jQuery.post(BASE_URL+"admin/dataman/buyer/deactivate",{user_id:$user_id},function(response){
		window.location.reload();
	});
}

function _delete($user_id){
	jQuery.post(BASE_URL+"admin/dataman/buyer/delete",{user_id:$user_id},function(response){
		window.location.reload();
	});
}

function _edit($user_id){
	jQuery.post(BASE_URL+"admin/dataman/buyer/edit",{user_id:$user_id},function(response){
		jQuery('#dialog').html(response);
		jQuery('#dialog').dialog(
			{
				 width: 950,
				 resizable: false,
				 height:500,
				 title: 'Edit Account Information'  
			}
		);
		
	});
}

function buyer_add(){
	jQuery.post(BASE_URL+"admin/dataman/buyer/add",{},function(response){
		jQuery('#dialog').html(response);
		jQuery('#dialog').dialog(
			{
				 width: 950,
				 resizable: false,
				 height:500,
				 title: 'Add Buyer Account'  
			}
		);
		
	});
}

jQuery(document).ready(function() {
	jQuery("#submit_information").live("submit",function(e){
		e.preventDefault(); // <-- important
		var options = { 
			beforeSubmit:  validateB4Submit,   
			success:       processAfterResponding   
		};	
		jQuery(this).ajaxSubmit(options);
		return false;
	});
	
	jQuery("#submit_add_account").live("submit",function(e){
		e.preventDefault(); // <-- important
		var options = { 
			beforeSubmit:  validateB4Submit,   
			success:       processAfterResponding   
		};	
		jQuery(this).ajaxSubmit(options);
		return false;
	}); 
});
 

function processAfterResponding(responseText, statusText, xhr, $form) {
	jQuery('#loader').hide();	
	 
	if(responseText == 'OK'){
		jQuery('#dialog').dialog('close');
		window.location.reload();
	}else{
		alert(responseText);
	}
}

function validateB4Submit(formData, jqForm, options){
	jQuery('#loader').show();
	
	json = {};
	for( e in formData){
		json[formData[e].name] = formData[e].value;
	}
	
	var arrayRequire = ['email','password','first_name','last_name','job_title','company','country','address_line_1','city','state','zip','work_phone']; 
	var err = 0;
	for(var i=0 ;i< arrayRequire.length; i++ ){
		if( isEmpty(json[arrayRequire[i]]) ){
			jQuery('#'+arrayRequire[i]+'_error').show();
			err++;
		}else{
			jQuery('#'+arrayRequire[i]+'_error').hide();
		}
	}
	
	if(err > 0){	
		jQuery('#loader').hide();
		alert("Error. Any fields are missing.");
		return false;
	}else{
		return true;
	}
}


















